<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/verify.jsp"%>
<jsp:include page="../common/meta.jsp"></jsp:include>
<jsp:include page="../common/easyui.jsp"></jsp:include>
<script type="text/javascript">
	var urlItemDataGrid;
	var editUrlItemWindow;
	var editUrlItemForm;
	var urlItemRowIndex;
	$(function() {
		// 		$('#urlItemLayout').layout();
		// 		$('#urlItemLayout').layout('collapse','north');

		urlItemDataGrid = $('#urlItemDataGrid').datagrid({
			url : '/com.sundaying.gooway/admin/listUrlItemJson',
			toolbar : '#toolbar',
			title : '网址列表',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [10, 20, 30],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : true,
			idField : 'itemID',
			columns : [[{
				title : '编码',
				field : 'itemID',
				width : 50,
				sortable : true
			}, {
				title : '网址名称',
				field : 'title',
				width : 200
			}, {
				title : '网址',
				field : 'url',
				width : 300
			}, {
				title : '网址分类',
				field : 'classID',
				width : 50
			}]],
			onSelect : function(rowIndex, rowData) {
				console.info('当前选择的行：' + rowIndex);
				urlItemRowIndex = rowIndex;
			},
			loadMsg : '加载中，请稍候...'
		});

		editUrlItemWindow = $('#editUrlItemWindow').window({
			closed : true,
			modal : true
		});

		editUrlItemForm = editUrlItemWindow.find('form');

		$('#btnSaveUrlItem').linkbutton();
		$('#btnCloseUrlItemWindow').linkbutton();

		// 加载网址分类列表选项
		$('#urlItemClassID').combobox({
			url : '/com.sundaying.gooway/admin/listUrlClassJson',
			valueField : 'classID',
			textField : 'className'
		});

		$('#condition_classID').combotree({
			url : '/com.sundaying.gooway/admin/treeUrlClassJson',
			multiple : true,
			cascadeCheck : false,
			required : true
		});
	});

	function newUrlItem() {
		console.info('增加...');
		editUrlItemWindow.window('open');
		editUrlItemWindow.find('#urlItemItemID').attr('readonly', false);
		editUrlItemForm.form('clear');
		editUrlItemForm.url = '/com.sundaying.gooway/admin/addUrlItemJson';
	}

	function editUrlItem() {
		console.info('修改...');
		// 选择最后选中的行
		urlItemDataGrid.datagrid('clearSelections');
		urlItemDataGrid.datagrid('selectRow', urlItemRowIndex);

		var row = urlItemDataGrid.datagrid('getSelected');
		if (row) {
			editUrlItemWindow.window('open');
			editUrlItemWindow.find('#urlItemItemID').attr('readonly', true);
			editUrlItemWindow.find('#urlItemItemID').val(row.itemID);
			editUrlItemWindow.find('#urlItemUrl').val(row.url);
			editUrlItemWindow.find('#urlItemTitle').val(row.title);
			console.info('row.classID...' + row.classID);
			if (row.classID != null) {
				editUrlItemWindow.find('#urlItemClassID').combobox('setValue',
						row.classID);
			}
			editUrlItemForm.url = '/com.sundaying.gooway/admin/updateUrlItemJson';
		} else {
			$.messager.alert('提示', '请选择要修改的记录！', 'error');
		}
	}

	function removeUrlItem() {
		console.info('删除...');
		var itemID = [];
		var rows = urlItemDataGrid.datagrid('getSelections');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						console.info(rows[i].itemID);
						itemID.push(rows[i].itemID);
					}
					$.ajax({
						url : '/com.sundaying.gooway/admin/deleteUrlItemJson',
						data : {
							itemID : itemID.join(',')
						},
						cache : false,
						dataType : "json",
						success : function(response) {
							urlItemDataGrid.datagrid('unselectAll');
							urlItemDataGrid.datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}

	// 保存新增分类
	function saveUrlItem() {
		console.info('保存...');
		if (editUrlItemForm.url == '') {
			editUrlItemForm.url = '/com.sundaying.gooway/admin/addUrlItemJson';
		}

		editUrlItemForm.form('submit', {
			url : editUrlItemForm.url,
			success : function(data) {
				console.info(data);
				editUrlItemWindow.window('close');
				urlItemDataGrid.datagrid('reload');
				$.messager.show({
					title : '提示',
					msg : '增加成功！'
				});
			},
			error : function(json) {
				console.info('保存出错！');
			}
		});
	}

	function closeUrlItemWindow() {
		editUrlItemWindow.window('close');
	}

	function searchUrlItem() {
		console.info('查询...');
		var urlClassID = $('#condition_classID').combotree('getValues');
		console.info("classID: " + urlClassID);
		urlItemDataGrid.datagrid('load', {
			urlClassID : urlClassID.join(',')
		});

		$.messager.show({
			title : '提示',
			msg : '查询成功！'
		});

	}

	function resetSearch() {
		console.info('清空查询条件');
		$('#searchBox input').val('');
		urlItemDataGrid.datagrid('load', {});
	}
</script>
<title>网址列表</title>
</head>
<body style="width: 720px; height: 520px; margin: 0 auto;">
	<div title="网址列表" border="false" closable="true"
		style="width: 100%; height: 100%;">
		<div id="urlItemLayout" class="easyui-layout"
			style="width: 100%; height: 100%;">
			<div region="north" border="false">
				<div id="searchBox">
					<fieldset>
						<legend>筛选</legend>
						<table class="tableForm">
							<tr>
								<th>网址分类</th>
								<td><input id="condition_classID" name="urlItem.classID"
									class="easyui-combotree" style="width: 105px;" /></td>
							</tr>
							<tr>
								<th>网址名称</th>
								<td colspan="2"><input name="urlItem.title"
									style="width: 305px;" /></td>
							</tr>
							<tr>
								<th>创建时间</th>
								<td colspan="2"><input name="urlItem.logCDate"
									class="easyui-datetimebox" editable="false"
									style="width: 150px;" />-<input name="createdatetimeEnd"
									class="easyui-datetimebox" editable="false"
									style="width: 150px;" /></td>
							</tr>
							<tr>
								<th>最后修改时间</th>
								<td><input name="urlItem.logUDate"
									class="easyui-datetimebox" editable="false"
									style="width: 150px;" />-<input name="modifydatetimeEnd"
									class="easyui-datetimebox" editable="false"
									style="width: 150px;" /></td>
								<td><a class="easyui-linkbutton" iconCls="icon-search"
									plain="true" onclick="searchUrlItem();"
									href="javascript:void(0);">查找</a><a class="easyui-linkbutton"
									iconCls="icon-search" plain="true" onclick="resetSearch();"
									href="javascript:void(0);">清空</a></td>
							</tr>
						</table>
					</fieldset>
				</div>
			</div>
			<div region="center" border="false"
				style="width: 100%; height: 100%; overflow: hidden">
				<div id="toolbar" class="datagrid-toolbar"
					style="height: auto; display: none;">
					<a class="easyui-linkbutton" iconCls="icon-add"
						onclick="newUrlItem();" plain="true" href="javascript:void(0);">增加</a>
					<a class="easyui-linkbutton" iconCls="icon-remove"
						onclick="removeUrlItem();" plain="true" href="javascript:void(0);">删除</a>
					<a class="easyui-linkbutton" iconCls="icon-edit"
						onclick="editUrlItem();" plain="true" href="javascript:void(0);">编辑</a>
					<a class="easyui-linkbutton" iconCls="icon-undo"
						onclick="datagrid.datagrid('unselectAll');" plain="true"
						href="javascript:void(0);">取消选中</a>
				</div>
				<table id="urlItemDataGrid"></table>
			</div>
		</div>
	</div>

	<div id="editUrlItemWindow" title="网址条目"
		style="width: 550px; height: 350px;">
		<div style="padding: 15px 15px 15px 15px;">
			<form method="post">
				<table>
					<tr>
						<td>网址编码：</td>
						<td><input id="urlItemItemID" name="urlItem.itemID"
							style="width: 150px"></input></td>
					</tr>
					<tr>
						<td>网址标题：</td>
						<td><input id="urlItemTitle" name="urlItem.title"
							style="width: 250px"></input></td>
					</tr>
					<tr>
						<td>网址地址：</td>
						<td><input id="urlItemUrl" name="urlItem.url"
							style="width: 350px"></input></td>
					</tr>
					<tr>
						<td>网址分类：</td>
						<td><input id="urlItemClassID" name="urlItem.classID"></td>
					</tr>
				</table>
			</form>
		</div>
		<div style="text-align: center; padding: 20px;">
			<a href="javascript:void(0)" onclick="saveUrlItem()"
				id="btnSaveUrlItem" icon="icon-save">保存</a> <a
				href="javascript:void(0)" onclick="closeUrlItemWindow()"
				id="btnCloseUrlItemWindow" icon="icon-cancel">取消</a>
		</div>
	</div>
</body>
</html>